<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h2>小黑自动售卖机</h2>
        <!-- <button v-if="money>=10:fn1"></button></button> -->
        <button @click="fn1(" 可乐",10)">可乐10元</button>
        <button @click="fn2(" 咖啡",10)">咖啡10元</button>
        <p>银行卡余额为：{{money}}</p>
    </div>
    <script src="js/vue.js"></script>
    <script>
        const app = new Vue({
            el: "#app",
            data: {
                money: 100
            },
            methods: {
                fn(name, p) {
                    if (this.money >= p) {
                        this.money -= p;
                    } else {
                        alert("余额不足,无法购买" + name);
                    }
                }
            }
        })
    </script>

</body>

</html>